var windowWidth = wx.getSystemInfoSync().windowWidth;
var windowHeight = wx.getSystemInfoSync().windowHeight;
var keyHeight = 0;
const app=getApp()
Page({
  data: {
    toView:'',
    scrollHeight: '100vh',
    inputBottom: 0,
    userAvatar:"",
    hasAvatar:false,
    msgList:[{
      speaker: 'server',
      content: '你说东我说西'
    },
    {
      speaker: 'customer',
      content: '你说鸭子我说鸡...'
    }
  ],
  inputVal:''
  },
  onLoad: function(options) {
this.setData({
  userAvatar:app.globalData.userInfo.avatarUrl,
  hasAvatar:true,
})
  },
  onShow: function() {
  },
  focus: function(e) {
    keyHeight = e.detail.height;
    this.setData({
      scrollHeight: (windowHeight - keyHeight) + 'px'
    });
    this.setData({
      toView: 'msg-' + (this.data.msgList.length - 1),
      inputBottom: keyHeight + 'px'
    })
  },
  blur: function(e) {
    this.setData({
      scrollHeight: '100vh',
      inputBottom: 0
    })
    this.setData({
      toView: 'msg-' + (this.data.msgList.length - 1)
    })
  },
  sendClick: function(e) {
    console.log(this.data.inputVal);
    let list=this.data.msgList;
list.push({
  speaker: 'customer',
  content: this.data.inputVal
});
    this.setData({
      inputVal:"",
      msgList:list
    });
    console.log(this.data);
  }
})